/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__topology_stat_show.c                            */
/*  NOTE      =                                                    */
/*  DATE      = 2015/02/02 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frmem.h"
#include "frsutl.h"
#include "frlist.h"
#include "frhash2.h"
#include "frstat_topology.h"
#include "apmtest_cunit.h"

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}

typedef struct __ip_list {
    u_int ui_ip;

} Frip_list;

typedef struct __topology {
    u_int   ui_dip;
    u_short us_dport;
    int     i_l7_proto;

    Frhash_header *p_st_hash_ip;

} Frstat_topology;

int __topology_stat_show(Frlist_node* p_node, const void *p_data);
void __topology_node_free(Frlist_node* p_node);


static void case1(void)
{
    int i_ret = 0;
    Frlist_node *p_node = NULL;
    Frip_list *p_Frip_list = NULL;
    Frstat_topology *p_stat_node = NULL;
    Frhash_header *p_st_hash_ip = NULL;
    int i_socket = 1;

    p_stat_node = (Frstat_topology *)frmalloc(sizeof(Frstat_topology));
    memset(p_stat_node, 0x00, sizeof(Frstat_topology));
    p_stat_node->ui_dip = iptools_parse_ipaddr("192.168.0.1");
    p_stat_node->us_dport = 80;
    p_stat_node->i_l7_proto = 1433;

    p_Frip_list = (Frip_list *)frmalloc(sizeof(Frip_list));
    memset(p_Frip_list, 0x00, sizeof(Frip_list));
    p_Frip_list->ui_ip = iptools_parse_ipaddr("192.168.1.1");

    p_node = frlist_node_create(p_Frip_list);
    p_st_hash_ip = frhash2_create2(50);
    frhash2_addLong(p_st_hash_ip, p_Frip_list->ui_ip, p_node);

    p_stat_node->p_st_hash_ip = p_st_hash_ip;

    p_node = frlist_node_create(p_stat_node);

    i_ret = __topology_stat_show(p_node, &i_socket);

    CU_ASSERT_EQUAL(i_ret,1);

    __topology_node_free(p_node);

    frfree(p_node);
    return;
}


int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t__topology_stat_show 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();

    return 0;
}